<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" %>
<%@ include file="../baselayout/import.jsp"%>
<style>
a{
text-decoration:none;
}
th,tr,td{
text-align: center;
}
</style>

<div>
	<div class="container-fluid">
		<a class="btn btn-primary" id="exportWechat">导出标记数据到文件</a>
		<a class="btn btn-primary" id="uploadWechatData">上传微信文本数据</a>
		<table class="table table-hover">
			<caption>Weka Arff格式数据集</caption>
			<thead>
					<tr>
					  <th>文件名</th>
					  <th>大小</th>
					  <th>上传者</th>
					  <th>最后修改时间</th>
					  <th colspan="3">操作</th>
					</tr>
			</thead>
		  <tbody>
			  <c:forEach var="x" items="${result}" >
					<tr>
						<td>${x.name}</td>
						<td>${x.size}</td>
				   		<td></td>
			   			<td><fmt:formatDate value="${x.lastModified}" pattern="yyyy/MM/dd HH:mm:ss"/></td>
						<td><a  href="${staticPath}/DataSet/TransArff.do"></a></td>
			   			<td><button class="btn btn-primary"  data-type='1' data-url='${staticPath}/dataset/delete.do?type=1&filename=${x.name}'>删除</button></td>
			   			<td><select name="classifierType">
			   				<option value="0">NaiveBayes</option>
			   				<option value="2">DT</option>
			   				<option value="3">SVM</option>
			   			</select></td>	
			   			<td><a  href="${staticPath}/DataSet/Establish.do?filename={{x.FileName}}">建立分类器</a>
			   				<c:choose>
								<c:when test="${x.size>100000 }">文件过大</c:when>
								<c:otherwise><a target="_blank" class="btn btn-primary" href='${staticPath}/dataset/preview.do?filename=${x.name}&type=1'>预览</a></c:otherwise>
							</c:choose>
			   			</td>	 
					</tr>
			  </c:forEach>
		  </tbody>
		</table>
		<table class="table table-hover">
			<caption>行文本文件数据集</caption>
			<caption>文档类别数目表,共有${totalDoc}文档</caption>
	      	<thead><tr><th>#</th><th>类别</th><th>文档数量</th><th>操作</th></tr></thead>
	      	<tbody>
				<c:forEach items="${eachClassCount}" var = "it" varStatus = "idx">
					<tr><th scope="row">${idx.index + 1 }</th><td class="lb"><c:out value="${it.key}" /> </td><td><c:out value="${it.value}" /> </td><td><button onclick="upload(this)" class="btn btn-default">上传该分类新数据文件</button><button onclick="del(this)" class="btn btn-default">删除该分类</button></td></tr>
				</c:forEach> 
				<tr>
					<td class="tfidf-tr text-center" colspan="5" class="text-center"><button type="button" id="tip" onclick="addNewClass('mkdir')" class="btn no-bg btn-contact">添加分类</button><button type="button" id="tip" onclick="window.location.reload()" class="btn no-bg btn-contact">刷新</button>
				</td>
			</tr>
			</tbody>
		</table>
		<table class="table table-hover">
			<caption>微信原始文件</caption>
			<thead>
					<tr>
					  <th>文件名</th>
					  <th>大小</th>
					  <th>上传者</th>
					  <th>最后修改时间</th>
					  <th colspan="3">操作</th>
					</tr>
			</thead>
		  <tbody>
			  <c:forEach var="x" items="${wechatfiles}" >
					<tr>
						<td>${x.name}</td>
						<td>${x.size}</td>
				   		<td></td>
			   			<td><fmt:formatDate value="${x.lastModified}" pattern="yyyy/MM/dd HH:mm:ss"/></td>
			   			<td><button class="btn btn-primary" data-url='${staticPath}/dataset/delete.do?type=4&filename=${x.name}' data-type='4' >删除</button></td>
			   			<td>
				   			<c:choose>
								<c:when test="${x.size>10000000 }">文件过大</c:when>
								<c:otherwise><a class="btn btn-primary" target="_blank" href='${staticPath}/dataset/preview.do?filename=${x.name}&type=4'>预览</a></c:otherwise>
							</c:choose>
			   			</td>	 
			   			<td>			   			
			   				<button id="" class="btn btn-info ladda-button" data-style="zoom-in"><span class="ladda-label">查询中</span></button>
			   				<input type="hidden" value="${staticPath}/admin/task/dotask.do?filename=${x.name}&command_type=command_type_word2vec_file_trans">
			   			</td>
					</tr>
			  </c:forEach>
		 	 </tbody>
		</table>
		<table class="table table-hover">
			<caption>文档ID-向量映射文件</caption>
			<thead>
					<tr>
					  <th>文件名</th>
					  <th>大小</th>
					  <th>上传者</th>
					  <th>最后修改时间</th>
					  <th colspan="3">操作</th>
					</tr>
			</thead>
		  <tbody>
			  <c:forEach var="x" items="${svmfiles}" >
					<tr>
						<td>${x.name}</td>
						<td>${x.size}</td>
				   		<td></td>
			   			<td><fmt:formatDate value="${x.lastModified}" pattern="yyyy/MM/dd HH:mm:ss"/></td>
			   			<td><button class="btn btn-primary" data-type='3' data-url='${staticPath}/dataset/delete.do?type=3&filename=${x.name}'>删除</button></td>
			   			<td><button class="btn btn-primary"  data-url="${staticPath}/dataset/trans.do?filename=${x.name }&type=3">转化SVM标准格式</button></td>
			   			<td>
			   				<c:choose>
								<c:when test="${x.size>10000000 }">文件过大</c:when>
								<c:otherwise><button class="btn btn-primary" data-url = "${staticPath}/dataset/preview.do?filename=${x.name}&type=3" >预览</button></c:otherwise>
							</c:choose>
			   				<a class="btn btn-primary" target="_blank" href="${staticPath}/dataset/tsne.do?filename=${x.name}&type=3">可视化</a>
			   			</td>	 
					</tr>
			  </c:forEach>
		 	 </tbody>
		</table>
		<script>
			!function(){
				//从数据库中导出标记好的微信到文本文件的前台接口
				function ex(){
					$.ajax({
						url:'${staticPath}/dataset/export.do?type=4',
						type:'get',
						success:function(data){
							console.log(data);
						},
						error:function(err){
							console.log(err);
						}
					});
				}
				//word2vec转换的接口,将指定的文件从后台发送给wod2vec服务进行转换
				function w2vtrans(url){
					$.ajax({
						url:url,
						type:'get',
						success:function(data){
							messageBox('success','转的成功',null);
							console.log(data);
						},
						error:function(err){
							messageBox('转的失败','服务器错误',null);
							console.log(err);
						}
					})
				}
				var querying = false;
				var queryBtn = null;
				$("#exportWechat").click(ex);
				//绑定菊花按钮的点击逻辑,如果得到boot微服务响应就更换事件函数.
				Ladda.bind( 'button.ladda-button', { 
					callback:function(laddabtn){
						if(querying){
							return ;
						}else{
							querying = true;
							queryBtn = laddabtn;
						}
						$.oAjax({
							url:'./queryWord2vecExist.do',
							success:function(data){
								Ladda.stopAll();
								data = JSON.parse(data);
								querying = false;
								if(data.code==200){
									if(typeof data.message.modelInfo.type != 'undefined'){
										if(data.message.modelInfo.type == 'file_mem'){
											$("button.ladda-button").each(function(){
												$(this).unbind('click');
												var url = $(this).next().val();
												$(this).click(function(){
													w2vtrans(url);
												}).html('W2V转换');
												//只有到这里,才可以进行转换
												return ;
											})
										}
									}
									
								}
								
								$("button.ladda-button").each(function(){
									$("span.ladda-label",this).html('重试')
								})
								
							},
							error:function(err){
								Ladda.stopAll();
								querying = false;
								$("button.ladda-button").each(function(){
									$(this).html('Web服务器错误')
								})
							}
						});
					}
				});
				//页面加载的时候去查询w2v服务器是不是开启.
				$("button.ladda-button").each(function(){
					$(this).click();
				})
				//绑定点击微信上传按钮之后的触发逻辑.
				$("#uploadWechatData").click(function(){
					var uploader = $("#uploader");
					var xhtml  = uploader.html();
					uploader.html('');
					messageBox('选择文件',xhtml,function(){

						uploader.html(xhtml);
					});
				});
			}();
		</script>
		<table class="table table-hover">
			<caption>LIBSVM-FORMAT 格式文件</caption>
			<thead>
					<tr>
					  <th>文件名</th>
					  <th>大小</th>
					  <th>上传者</th>
					  <th>最后修改时间</th>
					  <th colspan="3">操作</th>
					</tr>
			</thead>
		  <tbody>
			  <c:forEach var="x" items="${libsvm}" >
					<tr>
						<td>${x.name}</td>
						<td>${x.size}</td>
				   		<td></td>
			   			<td><fmt:formatDate value="${x.lastModified}" pattern="yyyy/MM/dd HH:mm:ss"/></td>
			   			<td><button class='btn btn-primary' data-url="${staticPath}/dataset/delete.do?type=5&filename=${x.name}">删除</button></td>
			   			<td><button class='btn btn-primary' data-url="${staticPath}/admin/svm/train.do?filename=${x.name }&command_type=svm_train">建立SVM分类器</button></td>
						<td>
			   				<c:choose>
								<c:when test="${x.size>10000000 }">文件过大</c:when>
								<c:otherwise><a class='btn btn-primary' target="_blank" href="${staticPath}/dataset/preview.do?filename=${x.name}&type=5" >预览</a></c:otherwise>
							</c:choose>
			   			</td> 	 
					</tr>
			  </c:forEach>
		 	 </tbody>
		</table>
	</div>
</div>
<div class="row"  id="uploader"  style="display:none;">
	<div style="width:100%" class="text-center">
		<form id="_i_dont_want_to_be_known_upload" method="post" action="../dataset/wechatupload.do" enctype="multipart/form-data" target="_blank">
        	<button class="btn btn-primary" type="button" onclick="!function(btn){$(btn).next().children('input[type=file]').click();}(this);" >选择文件文本文件</button>
	        	<div>
	        		<input id="_i_dont_want_to_be_known_file" style="display:none" type="file" name="file" onchange="!function(btn){var file = $(btn).val();if(typeof file == 'string' && file.length>0){$(btn).next().html(file);}}(this);">
	        		<div id="_i_dont_want_to_be_known_fn">选中的文件名将会显示到这里</div>
	        	</div>
        	<input type="submit" class="btn btn-info" value="提交">        
		</form>
		
	
	</div>
</div>
<script type="text/javascript">
!function(w){
	//修改本页面中有data-url属性的button请求方式为ajax,返回之后使用bootstrap模态框的方式显示提示,就是messageBox函数,是经过封装的在my.js里面
	$("button[data-url]").each(function(){
		var url = $(this).attr('data-url');
		$(this).click(function(){
			$.ajax({
				url:url,
				type:'get',
				success:function(data){
					messageBox('title',data,window.refreshSelf);
				},
				error:function(err){
					messageBox('title',err);
				}
			})	
		})
	
	});
	
}(window);


</script>
